/*
** pages.json里面页面.vue文件，必须写了onLoad函数，才会进入该js
*/
import { RouterMount, createRouter } from 'uni-simple-router';
import { Config } from './config.js';
const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});

var one = true
router.beforeEach((to, from, next) => {
	// console.log(to,'路由参数')
	
	// #ifdef MP-WEIXIN
	//如果是分享进来的
	if (to.query.scene) {
		one = true
	}
	// #endif
		
	let firstType = uni.getStorageSync("firstType");
	if (firstType) {
		one = false
	}
	let obj = {}
	if (one) {
		one = false
		if (to.path == '/pages/common/load') {
			obj.path = '/pages/home/index'
			obj.query = {}
			obj.fullPath = '/pages/home/index'
			uni.setStorage({ key: 'firstObj', data: obj })
			
			next();
		} else {
			obj.path = to.path
			obj.query = to.query
			obj.fullPath = to.fullPath
			uni.setStorage({ key: 'firstObj', data: obj })

			// #ifdef MP-WEIXIN
			next('/pages/common/load')
			// #endif
			
			// #ifdef H5
			uni.setStorage({ key: 'firstType', data: true })
			window.location.href = Config.http_h5_url + '/pages/common/load'
			// #endif
		}
		one = false
	} else {
		uni.setStorage({ key: 'firstType', data: false })
		next();
	}
});

// 全局路由后置守卫
router.afterEach((to, from) => {
	// console.log('跳转结束')
})

export {
	router,
	RouterMount
}
